<template>
  <div class="activity">
    <div class="table">
      <!-- <img src="@/assets/images/news_table.png" alt /> -->
      <p>
        {{ text }}
      </p>
    </div>
    <div class="two_nav clearfloat">
      <div class="two_nav_title">Activity</div>

      <div class="item_box">
        <swiper ref="swiper" :options="swiperOption">
          <swiper-slide
            v-for="(item, index) in cate_list"
            :key="index"
            class="swiper-slide"
          >
            <div
              :class="[
                currentId == item.id ? 'router-link-active' : '',
                'two_nav_item'
              ]"
              @click="onNavList(index, item.id, item.title)"
            >
              <span>{{ item.title }}</span>
            </div>
          </swiper-slide>
        </swiper>
      </div>
    </div>
    <router-view></router-view>
  </div>
</template>
<script>
import {
  activity_cate,
  activity_list,
  activity_recruit_add
} from "@/api/activity.js";
export default {
  data() {
    return {
      text: "",
      navActive: 0,
      cate_list: [],
      currentId: "",
      list: [],
      count: 1,
      currentPage: 1,
      swiperOption: {
        slidesPerView: "auto",
        spaceBetween: 0,
        // 鼠标控制滚动
        // mousewheel: {
        //   releaseOnEdges: true
        // },
        //设置点击箭头
        navigation: {
          nextEl: "#swiper-button-next",
          prevEl: "#swiper-button-prev"
        },
        observer: true, //修改swiper自己或子元素时，自动初始化swiper
        observeParents: false, //修改swiper的父元素时，自动初始化swiper
        //鼠标变成抓手型
        grabCursor: true
        //开启鼠标滚轮控制Swiper切换
        // mousewheel: true,
      }
    };
  },
  mounted() {
    this.getActivity_cate();
  },
  watch: {},
  methods: {
    //活动分类 列表
    getActivity_cate() {
      if (this.$store.state.headTitle.activityCateEN.length > 0) {
        this.cate_list = this.$store.state.headTitle.activityCateEN;
        if (this.$store.state.headTitle.activityCurrentEN) {
          this.currentId = this.$store.state.headTitle.activityCurrentEN;
          this.textFn(this.currentId);
        } else {
          this.currentId = this.cate_list[0].id;
          this.text = this.cate_list[0].title;
          this.$store.commit("changeActivityCurrentEN", this.cate_list[0].id);
        }
      } else {
        activity_cate().then(res => {
          this.cate_list = res.data.data;
          this.$store.commit("changeActivityCateEN", res.data.data);
          if (this.$store.state.headTitle.activityCurrentEN) {
            this.currentId = this.$store.state.headTitle.activityCurrentEN;
            this.textFn(this.currentId);
          } else {
            this.currentId = this.cate_list[0].id;
            this.text = this.cate_list[0].title;
            this.$store.commit("changeActivityCurrentEN", this.cate_list[0].id);
          }
        });
      }
    },
    //设置分类名
    textFn(id) {
      let index = this.cate_list.findIndex(item => item.id == id);
      this.text = this.cate_list[index].title;
      return;
    },
    //点击二级导航
    onNavList(index, id, text) {
      this.text = text;
      this.navActive = index;
      this.currentId = id;
      this.$store.commit("changeActivityCurrentEN", id);
      console.log(this.$router);
      if (this.$router.currentRoute.name == "en_activity_legalAidDetalis") {
        this.$router.push({
          name: "en_activity_legalAid"
        });
      }
    }
  }
};
</script>
<style scoped src="./sass/activity.css"></style>
